package com.example.controller;

import com.example.pojo.Coach;
import com.example.service.CoachService;
import com.example.utils.FileUtil;
import com.jcraft.jsch.SftpException;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/coach")
public class CoachController {
    @Autowired
    private CoachService coachService;

    @GetMapping("/getOne")
    public Coach selectCoachById(@Param("id") int id){
        return coachService.selectCoachById(id);
    }

    @GetMapping("/getAll")
    @CrossOrigin(origins="*")  // 允许所有源进行跨域请求
    public List<Coach> selectAllCoaches(){
        System.out.println("coachController被访问");
        List<Coach> coaches = coachService.selectAllCoaches();
        return coaches;
    }

    @GetMapping("/getByName")
    @CrossOrigin(origins="*")  // 允许所有源进行跨域请求
    public List<Coach> selectCoachByName(@RequestParam String name){
        return coachService.selectCoachByName(name);
    }

    @PostMapping ("/insert")
    @CrossOrigin(origins="*")  // 允许所有源进行跨域请求
    public int insertCoach(@RequestBody Coach coach) {
        System.out.println(coach.getPicurl());
        return coachService.insertCoach(coach);
    }

    @GetMapping("/delete")
    @CrossOrigin(origins="*")  // 允许所有源进行跨域请求
    public int deleteCoach(@RequestParam String id){
        System.out.println(id);
        int idInt = Integer.parseInt(id);
        return coachService.deleteCoachById(idInt);
    }

    @PostMapping("/updateCoach")
    @CrossOrigin(origins="*")  // 允许所有源进行跨域请求
    public int updateCoach(@RequestBody Coach coach){
        return coachService.updateCoach(coach);
    }

    @PostMapping("/updateMark")
    public int updateMark(float mark,int id){
        return coachService.updateMark(mark, id);
    }



}
